package proxy.staticproxy;

import java.text.SimpleDateFormat;
import java.util.Date;

public class OrderServiceStaticProxy implements IOrderService{
    private SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
    private IOrderService orderService;

    public OrderServiceStaticProxy(IOrderService orderService){
        this.orderService = orderService;
    }

    public int createOrder(Order order) {
     before();
     long time = order.getCreateTime();
     int dbRouter = Integer.valueOf(yearFormat.format(new Date(time)));
     System.out.println("Static Proxy auto set to [DB_" + dbRouter + "] datasource");
     DynamicDataSourceEntry.set(dbRouter);
     orderService.createOrder(order);
     after();
     return 0;
    }

    private void before() {
        System.out.println("Proxy before Method");
    }
    private void after() {
        System.out.println("Proxy after Method");
    }


}
